package org.mm.model;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;


/**
 * The persistent class for the drugs database table.
 *
 */
@Entity
@Table(name="drugs")
public class Drug implements Serializable {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 7640103417588883642L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="drug_id")
	private Long drugId;

	@Column(name="drug_creation_date")
	private Timestamp drugCreationDate;

	@Column(name="drug_last_modification_date")
	private Timestamp drugLastModificationDate;

	@Column(name="drug_quantity")
	private int drugQuantity;

	@Version
	@Column(name="drug_version")
	private int drugVersion;

	//bi-directional many-to-one association to DrugType
	@ManyToOne
	@JoinColumn(name="drug_type_id")
	private DrugType drugType;

	//bi-directional many-to-one association to Patient
	@ManyToOne
	@JoinColumn(name="drug_patient_id")
	private Patient patient;

	//bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name="drug_created_by_user")
	private User user1;

	//bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name="drug_last_modified_by_user")
	private User user2;

	//bi-directional many-to-one association to TherapyTask
	@OneToMany(mappedBy="drug", fetch=FetchType.EAGER)
	private List<TherapyTask> therapyTasks;

	public Drug() {
	}

	public Long getDrugId() {
		return this.drugId;
	}

	public void setDrugId(Long drugId) {
		this.drugId = drugId;
	}

	public Timestamp getDrugCreationDate() {
		return this.drugCreationDate;
	}

	public void setDrugCreationDate(Timestamp drugCreationDate) {
		this.drugCreationDate = drugCreationDate;
	}

	public Timestamp getDrugLastModificationDate() {
		return this.drugLastModificationDate;
	}

	public void setDrugLastModificationDate(Timestamp drugLastModificationDate) {
		this.drugLastModificationDate = drugLastModificationDate;
	}

	public int getDrugQuantity() {
		return this.drugQuantity;
	}

	public void setDrugQuantity(int drugQuantity) {
		this.drugQuantity = drugQuantity;
	}

	public int getDrugVersion() {
		return this.drugVersion;
	}

	public void setDrugVersion(int drugVersion) {
		this.drugVersion = drugVersion;
	}

	public DrugType getDrugType() {
		return this.drugType;
	}

	public void setDrugType(DrugType drugType) {
		this.drugType = drugType;
	}

	public Patient getPatient() {
		return this.patient;
	}

	public void setPatient(Patient patient) {
		this.patient = patient;
	}

	public User getUser1() {
		return this.user1;
	}

	public void setUser1(User user1) {
		this.user1 = user1;
	}

	public User getUser2() {
		return this.user2;
	}

	public void setUser2(User user2) {
		this.user2 = user2;
	}

	public List<TherapyTask> getTherapyTasks() {
		return this.therapyTasks;
	}

	public void setTherapyTasks(List<TherapyTask> therapyTasks) {
		this.therapyTasks = therapyTasks;
	}

	public TherapyTask addTherapyTask(TherapyTask therapyTask) {
		getTherapyTasks().add(therapyTask);
		therapyTask.setDrug(this);

		return therapyTask;
	}

	public TherapyTask removeTherapyTask(TherapyTask therapyTask) {
		getTherapyTasks().remove(therapyTask);
		therapyTask.setDrug(null);

		return therapyTask;
	}

}